#include <bits/stdc++.h>
using namespace std;
const int M = 60;
struct node {
  int type, id, score;
  bool operator<(const node &t) const {
    if (score == t.score) {
      if (type == t.type)
        return id > t.id;
      else
        return type > t.type;
    } else
      return score < t.score;
  }
};
priority_queue<node> pq;
queue<node> q;
unordered_set<int> del[M];
vector<int> ans[M];
int num[M], m, n;
int main() {
  cin >> m >> n;
  for (int i = 0; i < n; ++i) {
    int id, score;
    cin >> id >> score;
    for (int type = 0; type < m; ++type) pq.push({type, id, score});
  }
  int opnum;
  cin >> opnum;
  while (opnum--) {
    int op;
    cin >> op;
    if (op < 3) {
      int type, id;
      cin >> type >> id;
      if (op == 1) {
        int score;
        cin >> score;
        pq.push({type, id, score});
      } else
        del[type].insert(id);
    } else {
      int k;
      cin >> k;
      for (int i = 0; i < m; ++i) {
        cin >> num[i];
        ans[i].clear();
      }
      while (pq.size() && k) {
        auto x = pq.top();
        auto type = x.type, score = x.score, id = x.id;
        pq.pop();
        auto it = del[type].find(id);
        if (it != del[type].end()) {
          del[type].erase(it);
        } else {
          q.push(x);
          if (num[type]) {
            ans[type].push_back(id);
            k--, num[type]--;
          }
        }
      }
      while (q.size()) pq.push(q.front()), q.pop();
      for (int i = 0; i < m; ++i) {
        if (ans[i].size())
          for (auto el : ans[i]) cout << el << ' ';
        else
          cout << "-1";
        cout << endl;
      }
    }
  }
}
